package com.srcptit.trainning.tranquangvinh.b1;

public class Bai7LietKe {
	public static boolean Ngto(int n) {
		if(n<2) return false;
		if(n==2) return true;
		for(int i=2;i<=Math.sqrt(n);i++){
			if(n%i==0) return false;
		}
		return true;
	}
	public static boolean ThuanNghich(long n) {
		long tmp=n,s=0;
		while(tmp>0){
			s=s*10+tmp%10;
			tmp=tmp/10;
		}
		if(s==n) return true;
		return false;
	}
	public static int Fibo(int n) {
		if(n==0 || n==1) return 1;
		return(Fibo(n-1)+Fibo(n-2));
	}
	public static boolean TestFibo(int n) {
		int s=0;
		while(n>0){
			s=s+n%10;
			n=n/10;
		}
		int i=0,tmp;
		tmp=Fibo(i);
		while(s>tmp){
			tmp=Fibo(i++);
		}
		if(s==tmp) return true;
		return false;
	}
	public static void main(String []args) {
		for(int i=10000; i<9999999; i++){
			if(ThuanNghich(i))
				if(TestFibo(i))
					if(Ngto(i))
						System.out.print(i+" ");
		}
	}
}
